package com.hirel.persistence.common;

import java.util.List;

/**
 * @author PRAVEEN
 */

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hirel.IHirel;
import com.hirel.domain.common.UserDetailsDTO;

@Repository

public abstract class UserApplicationDAO implements IHirel,UserDetailsDAO{


	
	private Logger logger = Logger.getLogger("ExceptionLogger");
	
	@Autowired(required=true)
	private SessionFactory sessionFactory;

	@Override
	public void addUser(UserDetailsDTO userDetails) {
		sessionFactory.getCurrentSession().saveOrUpdate(userDetails);
	}

	@SuppressWarnings("unchecked")
	@Override
 	public List<UserDetailsDTO> listUsers(DetachedCriteria criteria) {
		
		 Session session=sessionFactory.getCurrentSession();
			List list=   criteria.getExecutableCriteria(session).list();
				
				return list;
				
	}

	@Override
	public UserDetailsDTO getUser(int userId) {
		 return (UserDetailsDTO) sessionFactory.getCurrentSession().get(UserDetailsDTO.class, userId);  
	}

	@Override
	public void deleteUser(UserDetailsDTO UserDetails) {
		sessionFactory.getCurrentSession().createQuery("DELETE FROM USER_DETAILS WHERE empid = "+UserDetails.getuserId()).executeUpdate(); 
	}


	
}
